<template>
  <el-dialog
    title="选择供应商"
    :visible.sync="dialogSupplierVisible"
    :before-close="selectSupplier"
    :close-on-click-modal="false"
    width="800px"
  >
    <!-- :inline="true" 表单一行显示 -->
    <el-form ref="searchForm" :inline="true" style="margin-top: 20px">
      <!-- 重置会看 el-form-item 组件元素的 prop 上是否指定了字段名，指定了才会重置生效 -->
      <el-form-item>
        <el-input
          v-model="searchMap.name"
          placeholder="供应商名字"
          style="width: 200px"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table
      ref="singleTable"
      :data="list"
      border
      stripe
      style="width: 100%"
      highlight-current-row
      @row-click="clickCurrentChange"
    >
      <el-table-column label="序号" width="100" type="index" :index="start">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="linkman" label="联系人"> </el-table-column>
    </el-table>

    <!-- 显示分页   layout="total, sizes, prev, pager, next, jumper"-->
    <el-pagination
      class="fenye"
      highlight-current-row
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"
      layout=" prev, pager, next"
      :total="total"
    >
    </el-pagination>
  </el-dialog>
</template>

<script>
import supplierApi from "@/api/supplier";
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      searchMap: {
        name: "",
      },

      list: [],
      total: 0,

      start: 1,
    };
  },

  props: ["dialogSupplierVisible", "selectSupplier"],

  created() {
    this.fetchData();
  },

  methods: {
    async fetchData() {
      const { data } = await supplierApi.search(
        this.currentPage,
        this.pageSize,
        this.searchMap
      );
      this.list = data.rows;
      this.total = data.total;
    },

    handleCurrentChange(val) {
      this.currentPage = val;
      this.fetchData();
    },

    search() {
      this.currentPage = 1;
      this.fetchData();
    },

    clickCurrentChange(currentRow) {
      this.selectSupplier(currentRow);
    },
  },
};
</script>

<style scoped>
</style>